home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-03 | 9.4 KB | 171 lines | [TEXT/MPS ] |
- (* Buffered input-output *)
-
- type in_channel (* input channels *)
- and out_channel (* output channels *)
- ;;
- exception End_of_file
- (* Raised when an operation cannot complete, because the end
- of the file is reached. *)
- ;;
- value std_in : in_channel
- and std_out : out_channel
- and std_err : out_channel
- (* The Unix standard input and outputs of the process. *)
- ;;
- value exit : int -> 'a
- (* Flushes all pending writes on std_out and std_err,
- and terminates the process with the given status code
- (usually 0 to indicate no errors, and a positive integer
- to indicate failure. This function MUST be called at
- the end of standalone programs that output results on
- std_out or std_err; otherwise, the program may appear
- to produce no output, or its output may be truncated. *)
- ;;
-
- value open_in : string -> in_channel
- (* Opens the named file for reading, and returns a new input channel
- on that file, positionned at the beginning of the file.
- Raises OS_error if the file could not be opened. *)
- and open_in_gen : int -> int -> string -> in_channel
- (* "open_in_gen mode rights filename" opens the file named
- filename for reading, as above. The integers mode and rights
- specify the opening mode (see unix__open). *)
- and open_descriptor_in : int -> in_channel = 1 "open_descriptor" "alloc"
- (* "open_descriptor_in fd" returns a buffered input channel
- reading from the file descriptor fd. fd must have been previously
- opened for reading (see unix__open, unix__pipe). *)
- and input_char : in_channel -> char = 1 "input_char"
- (* Reads one character from the given input channel.
- Raises End_of_file if there are no more characters to read. *)
- and input : in_channel -> string -> int -> int -> int = 4 "input"
- (* "input chan buff ofs len" attempts to read len characters
- from channel chan, storing them in string buf, starting at
- offset ofs. It returns the actual number of characters
- read, between 0 and len. On regular files, a return value
- less than len means that the end of the file was reached.
- On pipes, terminals, sockets, ..., a return value of 0
- usually means that the end of "file" was reached; a return
- value between 0 and len exclusive means that no more
- characters were available at that time. See the Unix man
- pages for read(2).
- Anything can happen if (ofs,len) does not correspond to a
- valid substring of buff. *)
- and input_byte : in_channel -> int = 1 "input_char"
- (* Same as input_char, but returns the 8-bit integer representing
- the character.
- Raises End_of_file if there are no more characters to read. *)
- and input_int : in_channel -> int = 1 "input_int"
- (* Reads four character from the given input channel, and
- returns the integer encoded by these characters. See output_int.
- Raises End_of_file if there are not enough characters to read. *)
- and input_value : in_channel -> 'a = 1 "intern_val" "alloc"
- (* Reads the representation of a structured value, as produced
- by output_value, and returns the corresponding value.
- THIS IS NOT TYPE-SAFE. The type of the returned object is
- not "'a" properly speaking: the returned object has one
- unique type, that cannot be determined at compile-time. The
- programmer must cast the returned value to the expected
- type, and be sure that the object in the file does belong
- to that type. *)
- and seek_in : in_channel -> int -> unit = 2 "seek_in"
- (* "seek_in chan pos" sets the current reading position to pos
- for channel chan. This works only for regular files. On
- pipes, terminals, sockets, ..., this does nothing, but does
- not fail either. *)
- and pos_in : in_channel -> int = 1 "pos_in"
- (* Returns the current reading position for the given channel.
- This works only for regular files. On pipes, terminals,
- sockets, ..., the result is meaningless. *)
- and in_channel_length : in_channel -> int = 1 "channel_size"
- (* Returns the total length (number of characters) for the
- given channel. This works only for regular files. On pipes,
- terminals, sockets, ..., the result is meaningless. *)
- and close_in : in_channel -> unit = 1 "close_in" "alloc"
- (* Closes the given channel. Anything can happen if any of the
- operations above is performed on a closed channel. *)
- ;;
- value open_out : string -> out_channel
- (* Opens the named file for writing, and returns a new output channel
- on that file, positionned at the beginning of the file. The
- file is truncated to zero length if it already exists. It
- is created if it does not already exists.
- Raises OS_error if the file could not be opened. *)
- and open_out_gen : int -> int -> string -> out_channel
- (* "open_out_gen mode rights filename" opens the file named
- filename for writing, as above. The integers mode and rights
- specify the opening mode (see unix__open). *)
- and open_descriptor_out : int -> out_channel = 1 "open_descriptor" "alloc"
- (* "open_descriptor_in fd" returns a buffered output channel
- reading from the file descriptor fd. fd must have been previously
- opened for writing (see unix__open, unix__pipe). *)
- and flush : out_channel -> unit = 1 "flush"
- (* Flushes the buffer associated with the given output channel,
- performing all pending writes on that channel.
- Interactive programs must be careful about flushing std_out
- at the right times. *)
- and output_char : out_channel -> char -> unit = 2 "output_char"
- (* Writes one character on the given output channel. *)
- and output_string : out_channel -> string -> unit
- (* Writes the given string on the given output channel. *)
- and output : out_channel -> string -> int -> int -> unit = 4 "output"
- (* "output chan buff ofs len" writes len characters from string
- buff, starting at offset ofs, to the output channel chan.
- Anything can happen if (ofs,len) does not correspond to a
- valid substring of buff. *)
- and output_byte : out_channel -> int -> unit = 2 "output_char"
- (* Writes one 8-bit integer on the given output channel. *)
- and output_int : out_channel -> int -> unit = 2 "output_int"
- (* Writes one integer as four characters on the given output channel.
- The only reliable way to read it back is through the
- input_int function. *)
- and output_value : out_channel -> 'a -> unit = 2 "extern_val"
- (* Writes the representation of a structured value of any type
- to a channel. Circularities and sharing inside the value
- are detected and preserved. The object can be read back,
- possibly in another process, by the function input_value. *)
- and seek_out : out_channel -> int -> unit = 2 "seek_out"
- (* "seek_out chan pos" sets the current writing position to pos
- for channel chan. This works only for regular files. On
- pipes, terminals, sockets, ..., this does nothing, but does
- not fail either. *)
- and pos_out : out_channel -> int = 1 "pos_out"
- (* Returns the current writing position for the given channel.
- This works only for regular files. On pipes, terminals,
- sockets, ..., the result is meaningless. *)
- and out_channel_length : out_channel -> int = 1 "channel_size"
- (* Returns the total length (number of characters) for the
- given channel. This works only for regular files. On pipes,
- terminals, sockets, ..., the result is meaningless. *)
- and close_out : out_channel -> unit = 1 "close_out" "alloc"
- (* Closes the given channel, flushing all buffered write operations.
- All opened output channels must be closed by hand at the
- end of a standalone program, to ensure that all written data
- will make its way through the Unix files and devices. *)
- ;;
- value print_char : char -> unit
- (* Prints one character on standard output. *)
- and print_string : string -> unit
- (* Prints one string on standard output. *)
- and print_int : int -> unit
- (* Prints one integer, in decimal, on standard output. *)
- and print_float : float -> unit
- (* Prints one floating-point number, in decimal, on standard output. *)
- and print_endline : string -> unit
- (* Prints one newline character on standard output. *)
- and print_newline : unit -> unit
- (* Prints one newline character on standard output, and flushes
- standard output. This can be used to simulate line
- buffering of standard output. *)
- ;;
- value prerr_char : char -> unit
- (* Prints one character on standard error. *)
- and prerr_string : string -> unit
- (* Prints one string on standard error. *)
- and prerr_int : int -> unit
- (* Prints one integer, in decimal, on standard error. *)
- and prerr_float : float -> unit
- (* Prints one floating-point number, in decimal, on standard error. *)
- and prerr_endline : string -> unit
- (* Prints one newline character on standard error. *)
- ;;
-